package com.xcc.mota.screen;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

import com.xcc.mota.sprite.BaseSprite;
import com.xcc.mota.sprite.NpcSprite;
import com.xcc.mota.sprite.PrincesSprite;
import com.xcc.mota.utils.BitmapLoad;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/1/19.
 */

public class Level1Screen extends BaseScreen {
    public Level1Screen(Context context) {
        super(context);
        paint = new Paint();
//32x32
//17x22+9
        initSprite();
    }

    private void initSprite() {
        princesSprite = new PrincesSprite(context);
        princesSprite.setMapIdx(1808);

        spriteList = new ArrayList<>();
        NpcSprite npcSprite = new NpcSprite(context);
        npcSprite.setMapIdx(708);
        spriteList.add(npcSprite);
        npcSprite = new NpcSprite(context);
        npcSprite.setMapIdx(710).setBitmapIdx(1);
        spriteList.add(npcSprite);
        npcSprite = new NpcSprite(context);
        npcSprite.setMapIdx(711).setBitmapIdx(2);
        spriteList.add(npcSprite);
        npcSprite = new NpcSprite(context);
        npcSprite.setMapIdx(905).setBitmapIdx(3);
        spriteList.add(npcSprite);
        npcSprite = new NpcSprite(context);
        npcSprite.setMapIdx(906).setBitmapIdx(4);
        spriteList.add(npcSprite);
    }

    private Paint paint;
    private PrincesSprite princesSprite;
    private List<NpcSprite> spriteList;
    private int map[][] = new int[][]{
            {206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206},
            {206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206},
            {206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206, 206},
            {206, 206, 206, 206, 206, 206, 206, 1060000, 1060000, 1060000, 206, 206, 206, 206, 206, 206, 206},
            {206, 206, 206, 206, 206, 206, 212, 1060000, 17000606, 1060000, 212, 206, 206, 206, 206, 206, 206},
            {206, 206, 206, 206, 1060000, 1060000, 1060000, 1060000, 606, 1060000, 1060000, 1060000, 1060000, 1060000, 206, 206, 206},
            {206, 206, 206, 212, 1060000, 1070000, 1070000, 1070000, 606, 1070000, 1070000, 1070000, 1070000, 1060000, 212, 206, 206},
            {206, 206, 206, 212, 1060000, 606, 606, 606, 606, 606, 606, 606, 606, 1060000, 212, 206, 206},
            {206, 206, 206, 212, 1060000, 606, 606, 606, 606, 606, 606, 606, 606, 1060000, 212, 206, 206},
            {206, 206, 206, 212, 1060000, 606, 606, 606, 606, 606, 606, 606, 606, 1060000, 212, 206, 206},
            {206, 206, 206, 212, 1060000, 606, 606, 606, 606, 606, 606, 606, 606, 1060000, 212, 206, 206},
            {206, 206, 206, 212, 1060000, 1060000, 1060000, 1060000, 606, 606, 1060000, 1060000, 1060000, 1060000, 212, 206, 206},
            {206, 206, 206, 212, 1070000, 1070000, 1070000, 1060000, 606, 606, 1060000, 1070000, 1070000, 1070000, 212, 206, 206},
            {206, 206, 206, 206, 206, 206, 212, 1060000, 606, 606, 1060000, 212, 206, 206, 206, 206, 206},
            {206, 206, 206, 206, 206, 206, 212, 1060000, 606, 606, 1060000, 212, 206, 206, 206, 206, 206},
            {206, 206, 206, 206, 206, 206, 212, 1060000, 606, 606, 1060000, 212, 206, 206, 206, 206, 206},
            {206, 206, 206, 206, 206, 206, 212, 1060000, 606, 606, 1060000, 212, 206, 206, 206, 206, 206},
            {206, 206, 206, 206, 206, 206, 212, 1060000, 606, 606, 1060000, 212, 206, 206, 206, 206, 206},
            {206, 206, 7000206, 7000206, 7000206, 206, 212, 1060000, 606, 606, 1060000, 212, 206, 7000206, 7000206, 7000206, 206},
            {206, 7000206, 7010206, 7000206, 7010206, 7000206, 212, 1060000, 606, 606, 1060000, 212, 206, 7010206, 7000206, 7010206, 206},
            {206, 7000206, 206, 7000206, 206, 7000206, 212, 1060000, 606, 606, 1060000, 212, 206, 206, 7000206, 206, 206},
            {206, 7010206, 206, 7010206, 206, 7010206, 212, 1060000, 606, 606, 1060000, 212, 206, 206, 7010206, 206, 206},
            {206, 206, 206, 206, 206, 206, 206, 1070000, 609, 609, 1070000, 206, 206, 206, 206, 206, 206}
    };

    public void onDraw(Canvas canvas) {
        //画背景32x32
        BitmapLoad bitmapLoad = BitmapLoad.getInstance(context);
        for (int i = 0; i < map.length; i++) {
            int[] ints = map[i];
            for (int j = 0; j < ints.length; j++) {
                int idx = ints[j];
                int idx2 = 0;
                if (idx > 10000) {
                    idx2 = idx % 10000;
                    idx = idx / 10000;
                }
                if (idx2 > 0) {
                    Bitmap bitmap = bitmapLoad.getBitmap(0, idx2);
                    canvas.drawBitmap(bitmap, 32 * j, 32 * i, null);
                }
                if (idx > 0) {
                    Bitmap bitmap = bitmapLoad.getBitmap(0, idx);
                    canvas.drawBitmap(bitmap, 32 * j, 32 * i, null);
                }
            }
        }

        princesSprite.onDraw(canvas, paint);
        for (BaseSprite sprite : spriteList) {
            sprite.onDraw(canvas, paint);
        }
    }
}
